package com.zhouyu;

import org.springframework.boot.context.event.ApplicationEnvironmentPreparedEvent;
import org.springframework.boot.context.event.EventPublishingRunListener;
import org.springframework.context.ApplicationListener;
import org.springframework.stereotype.Component;


/**
 *
 * 监听器
 * ApplicationEnvironmentPreparedEvent 事件在spring.factories 需要定义
 *
 * 1. SpringApplicationRunListener的starting()   ApplicationContextInitializedEvent
 *
 * 2.SpringApplicationRunListener的environmentPrepared()  EnvironmentPostProcessorApplicationListener
 *
 *
 * 3.SpringApplicationRunListener的contextPrepared()  EventPublishingRunListener
 *
 * 4.SpringApplicationRunListener的contextLoaded()  EventPublishingRunListener
 *
 * 5.SpringApplicationRunListener的started()  ApplicationStartedEvent和 AvailabilityChangeEvent
 *
 * 6.SpringApplicationRunListener的ready() ApplicationReadyEvent AvailabilityChangeEvent
 *
 *
 * 7.异常了就触发SpringApplicationRunListener的failed()  ApplicationFailedEvent事件
 *
 *
 *
 * 【重要】
 * {@link  EventPublishingRunListener#environmentPrepared}
 */
public class MyApplicationListener implements ApplicationListener<ApplicationEnvironmentPreparedEvent> {


	@Override
	public void onApplicationEvent(ApplicationEnvironmentPreparedEvent event) {
		System.out.println(event.getEnvironment());
	}
}
